package com.arc.spring.proxy.statical;

/**
 * @author YangYunhe
 * @date 2024/12/30
 * @description 静态代理
 * 代理类和被代理类要实现同一个接口，一个静态代理类只能代理一个类
 */
public class StaticProxyDemo {

    public static void main(String[] args) {

        Person person = new Person("张三");
        Lawyer lawyer = new Lawyer(person);
        lawyer.defense();

    }

}

/**
 * 法庭
 */
interface Court {

    /**
     * 辩护
     */
    void defense();

}

/**
 * 当事人：被代理类
 */
class Person implements Court {

    private String name;

    public Person(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public void defense() {
        System.out.println(name + "说：我的是清白的");
    }
}

/**
 * 律师：代理类，对被代理类的功能进行增强
 */
class Lawyer implements Court {

    private Person person;

    public Lawyer(Person person) {
        this.person = person;
    }

    @Override
    public void defense() {
        System.out.println("律师说：" + person.getName() + "不在现场！");
        person.defense();
    }

}
